<?php
namespace App\Http\Controllers\Pay;

use App\Http\Controllers\Controller;

/**
 * 微信支付退款实现类
 */
 
class WxPayRefundController extends Controller {
	
	public function __construct(){
		header("Content-type:text/html;charset=utf-8");
		//微信退款API
		require_once(app_path().'/Library/Wxpay/lib/WxPayConfig.php');
		require_once(app_path().'/Library/Wxpay/lib/WxPayData.php');
		require_once(app_path().'/Library/Wxpay/lib/WxPayException.php');
		require_once(app_path().'/Library/Wxpay/lib/WxPayNotify.php');
		require_once(app_path().'/Library/Wxpay/lib/WxPayApi.php');
		require_once(app_path().'/Library/Wxpay/log.php');
		
		date_default_timezone_set('Asia/Shanghai');
    }
	
	function wxRefund($info){
		$input = new \WxPayRefund();
		$info["out_trade_no"] && $input->SetOut_trade_no($info["out_trade_no"]);
		$info["transaction_id"] && $input->SetTransaction_id($info["transaction_id"]);
		$input->SetTotal_fee($info["total_fee"]);
		$input->SetRefund_fee($info["refund_fee"]);
		$input->SetOut_refund_no(date("YmdHis"));
		$input->SetOp_user_id(\WxPayConfig::MCHID);
		$info = \WxPayApi::refund($input);
		
		$parameters = json_encode($info);
		return $parameters;
	}
}